﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Destination Pdf Demo</title>
    <!--Look the src of styles included files. They are relative.
        The HTMLShot DLL work to convert them to full uri path.-->
    <link href="Styles/DestinationPDF.css" rel="stylesheet" type="text/css" media="screen"/>
    <script src="Scripts/DestinationPDF.js" type="text/javascript"></script>
    <script type="text/javascript">
        var submitData;
    </script>
</head>
<body style="background:#2C2C2C;
    margin:0px;
    top:0px;
    left:0px;
    font-family:Calibri,Microsoft Sans-Serif Serif,Tahoma;
    font-style:normal;
    font-weight:normal;
    font-size:12px;
    color:#171717;
">
    <form id="form">
        <p>Choose html objects to export to pdf :</p>            
        <input id="atkCheck" type="checkbox" checked="checked"/>Title &nbsp;  <br/>
        <input id="pictureCheck" type="checkbox" checked="checked"/>Image &nbsp; <br/>
        <input id="tableCheck" type="checkbox" checked="checked"/>HTML Table &nbsp; <br/>
        <input id="textPDFCheck" type="checkbox" checked="checked"/>Text &nbsp; <br/>
        <br />
        <center><input type="button" value="Generate PDF" onclick="submitData()"/></center>
    </form>
    <center>
        <div class="template">
            <center>
                <div class="title">Destination PDF Example</div>
                <div class="sample">
                    <div class="globalContainer">
                        <div id="atkContainer">                        
                            <div class="atk">
                                <div>
                                    <div class="atkLogoContainer"><img src="Styles/ImagesDestinationPDF/atk_logo.png" alt=""/></div>
                                    <div class="atkSubContainer" >
                                        <div class="atkTitle">Australtek</div>
                                        <div class="atkDemo">Destination PDF Demo</div>
                                    </div>
                                </div>
                                <div class="atkDescription">AustralTek offers complete automation solutions, from the concept to onsite implementation.</div>
                            </div>
                        </div>
                        <div id="pictureImageContainer">
                            <img id="pictureImage" class="pictureImages" src="Styles/ImagesDestinationPDF/pdfImage.jpg" alt=""/>
                        </div>
                        <div id="tableImageContainer">
                            <table id="tableImage" class="tableImages" border="1">
                                <tr>
                                    <td rowspan="2">Hello</td><td>World</td><td>!!!</td>
                                    <td rowspan="2">Hello</td><td>World</td><td>!!!</td>
                                </tr>
                                <tr class="">
                                    <td>World</td><td>???</td><td>World</td><td>???</td>
                                </tr>
                                <tr class="">
                                    <td colspan="6" style="text-align:center">H e l l o  W o r l d</td>
                                </tr>
                            </table>
                        </div>

                        <div id="textPDFContainer" class="textPDFContainers">
                            <div>Edit this text if you wish :</div>
                            <textarea id="textPDF" rows=10 cols=70>
                                Jorge Francisco Isidoro Luis Borges Acevedo (August 24, 1899 – June 14, 1986), best known as Jorge Luis Borges, was an Argentine writer, essayist, and poet born in Buenos Aires.
                                In 1914 his family moved to Switzerland where he attended school and traveled to Spain. On his return to Argentina in 1921, Borges began publishing his poems and essays in surrealist literary journals.
                                He also worked as a librarian and public lecturer. In 1955 he was appointed director of the National Public Library (Biblioteca Nacional) and professor of Literature at the University of Buenos Aires.
                                In 1961 he came to international attention when he received the first International Publishers' Prize, the Prix Formentor. His work was translated and published widely in the United States and in Europe. Borges himself was fluent in several languages. He died in Geneva, Switzerland, in 1986.
                                His work embraces the "chaos that rules the world and the character of unreality in all literature.
                                "His most famous books, Ficciones (1944) and The Aleph (1949), are compilations of short stories interconnected by common themes: dreams, labyrinths, libraries, fictional writers and works, religion, God. His works have contributed significantly to the genre of magical realism. Scholars have noted that Borges's progressive blindness helped him to create innovative literary symbols through imagination since "poets, like the blind, can see in the dark". The poems of his late period dialogue with such cultural figures as Spinoza, Luís de Camões, and Virgil.
                                His international fame was consolidated in the 1960s, aided by the "Latin American Boom" and the success of Gabriel García Márquez's Cien Años de Soledad.
                                Writer and essayist J. M. Coetzee said of him: "He, more than anyone, renovated the language of fiction and thus opened the way to a remarkable generation of Spanish American novelists.
                            </textarea>
                        </div>
                    </div>
                </div>
                <div class="content" style='text-align:left;padding:20px'>
                <p> In this example, the javascript code needed to export some widgets to pdf is:  </p>
                <pre style=' background-color:#E0E0F0'>

        var destinationPdf = new DestinationPDF({ 'URL': 'ServerScripts/DestinationPdf.aspx' });

        var titlePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
        titlePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('atkImageContainer').innerHTML), 
                                    'FullPath': window.location.href });
        destinationPdf.addPdfWidget(titlePDFWidget);

        var picturePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
        picturePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('pictureImageContainer').innerHTML), 
                                        'FullPath': window.location.href });
        destinationPdf.addPdfWidget(picturePDFWidget);

        var tablePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
        tablePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('tableImageContainer').innerHTML), 
                                    'FullPath': window.location.href });
        destinationPdf.addPdfWidget(tablePDFWidget);

        var pdfWidget = new PdfWidget({ 'type': 'HTMLText' });
        pdfWidget.setContent({ 'value': document.getElementById('textPDF').value });
        destinationPdf.addPdfWidget(pdfWidget);

        destinationPdf.sendData();
                </pre>
                </div>
            </center>
        </div>
    </center>

    <script type="text/javascript">
        submitData = function () {
            try {
                /*
                The Destination PDF library can export to pdf all what you want.
                First, you have to instance the Javascript Destination PDf Class and then push it some PDF Widgets objects.
                For the PDf WIdgets you have to set their "content" depending what they are because the structure what you set then
                will be 'Deserialize it" to a C# Class Object.
                This last has to implement the "Destiantion PDF Interface". In the "DrawToPDF" method of that interface each object to export
                has to have how it export to pdf itself, using the PDFSharp and Migradoc Libraries.
                */

                //Instance the Destination PDf Class, with the URL what procces the data and build the pdf file.
                var destinationPdf = new DestinationPDF({ 'URL': 'ServerScripts/DestinationPdf.aspx' });

                //Only send the widgets what the user has been chosen.
                if (document.getElementById('atkCheck').checked == true) {
                    //Instance the PDf Widget Class, with the type of the widget to export to pdf.
                    var titlePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
                    //Set the contetn of the widget to eport depending its type.
                    titlePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('atkContainer').innerHTML), 'FullPath': window.location.href });
                    destinationPdf.addPdfWidget(titlePDFWidget);
                }

                if (document.getElementById('pictureCheck').checked == true) {
                    var picturePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
                    picturePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('pictureImageContainer').innerHTML), 'FullPath': window.location.href });
                    destinationPdf.addPdfWidget(picturePDFWidget);
                }

                if (document.getElementById('tableCheck').checked == true) {
                    var tablePDFWidget = new PdfWidget({ 'type': 'HTMLStruct' });
                    tablePDFWidget.setContent({ 'HTMLString': getHtmlString(document.getElementById('tableImageContainer').innerHTML), 'FullPath': window.location.href });
                    destinationPdf.addPdfWidget(tablePDFWidget);
                }

                if (document.getElementById('textPDFCheck').checked == true) {
                    var pdfWidget = new PdfWidget({ 'type': 'HTMLText' });
                    pdfWidget.setContent({ 'value': document.getElementById('textPDF').value });
                    destinationPdf.addPdfWidget(pdfWidget);
                }

                destinationPdf.sendData();
            }
            catch (Error) { window.status = Error.Message; }
        }
    </script>
</body>
</html>